home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 8 / Mac Magazin and MacEasy Magazine CD - Issue 08.iso / Sharewarebibliothek / Updater⁄Infos / Mausefalle 1.1.2 -> 1.1.3 / Terminal 2.2 Skript < prev   
Text File  |  1993-08-29  |  4KB  |  187 lines

  1. /*
  2.     Terminal 2.0 script
  3.  
  4.     Login and do "Maustausch" with Maus AC
  5. */
  6.  
  7. int flg;
  8. int err,outfile_err,infile_err;
  9. int timeout = 1800;                            /* 30 seconds */
  10. int redial_t = 1800;                        /* Redial-Time = 30s */
  11. char line[80];
  12. char init_s[] = "ATZ\r";                    /* modem init-string */
  13. char prefix[] = "ATDP";                        /* dial-string */
  14. char number[] = "500482";                    /* number for Maus AC */
  15. char user_name[] = "Frank Sample\r";        /* user name */
  16. char password[] = "geheim\r";                /* password */
  17. char infile [32] = "infile.Txt";
  18. char outfile [32] = "outfile.txt";
  19.  
  20.  
  21. hangup()
  22. {
  23.     pause(120);
  24.     check("+++","OK",300);    /* Go into command mode */
  25.     type("ATH0\r");            /* Hang up */
  26.     beep();
  27. }
  28.  
  29. /* ----- Send command and wait for reply ------------------------------- */
  30.  
  31. check(char *command, char *reply, int timeout)
  32. {
  33.     type(command);
  34.     return prompt(reply, timeout);
  35. }
  36.  
  37. /* ----- Wait for prompt and send command ------------------------------ */
  38.  
  39. answer(char *hint, char *command)
  40. {
  41.     int result;
  42.  
  43.     if (result = prompt(hint, timeout))
  44.         return result;    /* Timeout or cancel */
  45.     pause(30);            /* Don't type immediatly */
  46.     type(command);
  47.     return 0;
  48. }
  49.  
  50. /* ----- Strip leading control characters (like LFs) ------------------- */
  51.  
  52. Strip(char *line)
  53. {
  54.     while (*line && (*line < 0x20 || *line > 0x7E))
  55.         ++line;
  56.     return line;
  57. }
  58.  
  59. /* ----- Initialyse modem and terminal ---------------------------------- */
  60.  
  61. init()
  62. {
  63.     err = 0;
  64.     
  65.     terminal (0,0,0,1);
  66.     setup(
  67.         8,        /* 8=57600 baud */                /* refer to your modem-manual! */
  68.         1,        /* 8 data */
  69.         0,        /* no parity */
  70.         0,        /* 1 stop */
  71.         -1,        /* port: no change */
  72.         -1,        /* DTR: no change */
  73.         4);        /* 4=Handshake: CTS/DTR */
  74.     if (check(init_s, "OK", 600)) {                /* Modem init */
  75.         err = 1;
  76.         display ("No modem connected?\r");        /* no modem */
  77.         return 0;
  78.     }
  79.     pause(30);
  80.     return 1;
  81. }
  82.  
  83. /* ----- if no infile.txt take default infile --------------------------*/
  84.  
  85. set_infile()
  86. {
  87.     char fname;
  88.     int ftype,fdsize,frsize,fcdate,fmdate;
  89.  
  90.     err = catalog (0,infile,&ftype,&fdsize,&frsize,&fcdate,&fmdate);
  91.     if (err) {
  92.         infile = def_infile;
  93.         return;
  94.     }
  95.     if (fdsize <= 2)
  96.         infile = def_infile;
  97. }
  98.  
  99. delete_infile()
  100. {
  101.     if (!infile_err) {                        /* if upload ok */
  102.         if (strcmp(infile,def_infile)) {
  103.             capture(1,infile);                /* deletes contents of infile */
  104.             display("#\r");
  105.             capture(0,infile);
  106.         }
  107.     }
  108. }
  109.  
  110.  
  111. /* ----- Connect with mailbox -------------------------------------------*/
  112.  
  113. connect()
  114. {
  115.     char *s;
  116.     int repeat = 1;
  117.     
  118.     while (repeat) {
  119.         display ("Dialing for mailbox -- ");
  120.         type ("%s%s\r",prefix , number);    /* dial number */
  121.         pause(120);        
  122.         if (!(err = prompt("CONNECT",timeout+900)))    { /* repeat if busy */
  123.             display ("connect\r");
  124.             repeat = 0;
  125.         }
  126.         else
  127.             display ("busy\r");
  128.         if (err == 2) {
  129.             display ("Dial canceled! (err=%i)\r",err);
  130.             return 0;
  131.         }
  132.     }
  133.     return 1;
  134. }
  135.             
  136. /* ----- log into mailbox -------------------------------------------------*/
  137.  
  138. login()
  139. {
  140.     int ok = 1;
  141.     
  142.     while (ok) {
  143.         if (answer("(J/N)","MausTausch"))
  144.             break;
  145.         type("%s", user_name);
  146.         type("%s", password);
  147.         ok = 0;
  148.     }
  149.     if (!ok) {
  150.         display ("Login successful!\r");
  151.  
  152.     }
  153. }
  154.  
  155. logoff()
  156. {
  157.     hangup();
  158. }
  159.  
  160. maustausch()
  161. {
  162.     answer("Protokoll:","Z");
  163.     prompt("Protokoll startet",timeout);
  164.     display ("Sending InFile!\r");
  165.     infile_err = upload (infile,0,1);            /* no MacBinary, use Z-Modem */
  166.     prompt("Protokoll startet",timeout);
  167.     display ("Receiving OutFile!\r");
  168.     outfile_err = download (outfile,1,1);        /* detect MacBinary, use Z-Modem */
  169. }
  170.  
  171. /* ----- Main program -------------------------------------------------- */
  172.  
  173. main()
  174. {
  175.     save (0);
  176.     set_infile();
  177.     if (init())
  178.         if (connect()) {
  179.             login();
  180.             maustausch();
  181.             logoff();
  182.             delete_infile();
  183.         }
  184.     save(1);
  185.     return 257;                             /* exit programm */
  186. }
  187.